Skip to content

feat: show a real WebKit page in the Mac card's Browser tab - #19

Merged
Alex793x merged 7 commits into
devfrom
claude/mac-native-card-browser
Nov 23, 2026
Merged

Alex793x merged 7 commits into
devfrom
claude/mac-native-card-browser

Conversation

@Alex793x

@Alex793x Alex793x commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Change

On the Mac, a card's Browser tab used to show screenshots of a hidden headless Chrome. Scrolling
blanked the page, and frames arrived 3–4 times a second. Google also answered searches with its
"unusual traffic" page, because that Chrome reports itself as HeadlessChrome with
navigator.webdriver set.

  • Headless frames fixed (render.ts, manager.ts). The screenshot clip now starts where the
    page is scrolled, and live frames are JPEG: about 40 ms a frame at 2× instead of 133 ms, and about
    130 KB instead of 530 KB. macOS 13 and Linux still use these frames.
  • BrowserEngine port (runtime/browser/engine.ts). The manager talks to an engine. Headless
    Chrome and WebView2 now sit behind Playwright adapters in playwright-engine.ts. pool.ts and
    native-pool.ts are unchanged.
  • A real WebKit page on macOS 14 and later (src-tauri/src/browser/macos/,
    runtime/browser/webkit-engine.ts). A WKWebView sits over the card, the way WebView2 does on
    Windows, so scrolling is native.
    • The page uses WebKit's own user agent, unmodified.
    • Each card has its own lasting website data.
    • Pages get no bridge to MemCode.
    • Plain http: is blocked except for localhost.
    • Camera, microphone and downloads are refused.
  • Workers drive the same page (webkit-driver.ts, webkit-accessibility.ts). They have the
    same tools and the same text format as on Windows: click, type, press, choose, scroll, hover,
    and observe with an aria-snapshot tree. A click, key press or scroll by the person in the card
    takes control from the worker.
    • Worker clicks on select, file, date, time and color controls are refused, because WebKit
      would open a native panel. Use choose or type instead.
  • Self-closing pages close their tab (self_close.rs). A popup that calls window.close(),
    such as an OAuth sign-in, now closes its tab.

These seven commits were first made on top of test/sharing-two-computers. They are replayed here
onto dev without any of the sharing commits, and the diff is byte-identical to the build that was
tested.

Validation

On a Mac (macOS 27.2, Apple silicon), at this branch's head:

  • npm ci, then npm run typecheck: passed.
  • npm test: 1,183 tests, 1,180 passed, 0 failed, 3 skipped.
  • npm run build: passed.
  • cargo test in src-tauri: 46 passed, 1 ignored. The three unused-import warnings it prints
    (beta_store.rs, browser.rs lines 3–4) are in lines this branch doesn't change, and they show
    on dev too.

Earlier, on the same diff before the replay:

  • scripts/macos-cold-start.mjs passed against a release MemCode.app built from it. The native
    process started, the bundled Node was used, and the renderer reached workspace:load. It was not
    rerun on this branch.
  • Alex tried Google search and trackpad scrolling in the card's Browser tab of a debug build of it
    and reported that it works much better.

Still pending:

  • Windows. WebView2 now goes through the new port, so it needs a check on the PC.

    1. npm ci, node scripts/prepare-desktop-runtime.mjs, npm run dev.
    2. Open a card's Browser tab and scroll a long page.
    3. Save a browser screenshot halfway down. It should show the part you were looking at.
    4. Start a worker that uses the browser and check it still clicks, types and observes as before.

    The Windows Rust target was not compile-checked, because ring needs a Windows C toolchain.

  • Not tried by hand in the app yet: a worker driving the Mac page, and a sign-in popup closing
    itself. Both are covered by tests and by a scratch WKWebView harness.

  • Known gaps:

    • Observe covers only the main frame, as on the other platforms. Clicks at a point do reach
      iframes.
    • The page sees a worker's click into a text field as a blur and then a focus, because
      keyboard focus is handed back to whatever had it.

User impact

On macOS 14 and later, each card now keeps its own browser cookies and sign-ins across restarts.
WebKit stores them under ~/Library/WebKit/<bundle id>/WebsiteDataStore/. The old headless browser
kept nothing between sessions. Saved projects, settings and updates are unchanged.

🤖 Generated with Claude Code


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Alex793x and others added 7 commits November 23, 2026 12:47
On macOS a card's Browser tab is a stream of screenshots from headless
Chrome. The capture passed a clip at 0,0, but Chrome reads the clip in
page coordinates. Once the page scrolled, the clip pointed above the
viewport and those rows came back blank: scroll 300px and the top 300px
of the frame was empty, scroll a full screen and nothing was left.

Start the clip at the visual viewport's page offset, which is what
Playwright does for its own screenshots. Windows shows the live WebView2
surface and doesn't use this capture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each live frame was a lossless PNG at Retina density. In the Mac app
that took 133ms on average to capture, up to 284ms, and came to about
530KB of base64. Scrolling showed three or four frames a second, each
one late.

JPEG at quality 85 takes about 40ms and 130KB for the same page, so a
scroll now lands at roughly 8 frames a second with nothing queued
behind it. Text stays sharp at 2x.

Only the live frame changes. Screenshots a worker observes and ones
saved to a card's artifacts stay PNG, and the Windows WebView2 capture
is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two behaviours the browser tests never checked: a card page can't load
plaintext from a host other than this machine, and a target=_blank link
opens as another tab of the same card. Both pass on the current code and
fail when the route or the popup listener is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The manager now talks to one interface instead of Playwright pages.
Headless Chrome and WebView2 sit behind Playwright adapters in
playwright-engine.ts; pool.ts and native-pool.ts are unchanged, so the
Windows calls happen in the same order as before. The capture tests only
change how they reach the manager's internals.

This is where the Mac's native WebKit surface plugs in next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On macOS 14 and later a card's Browser tab is now a WKWebView placed
over the card, like the WebView2 surface on Windows, instead of JPEG
frames from headless Chrome. Google and other sites see an ordinary
WebKit browser, and scrolling is native.

- One WebKit data store per card, kept between launches.
- Guest pages get no bridge; MemCode's scripts run in their own content
  world. Plaintext only reaches this machine (content rules plus the
  navigation check). Camera, microphone and downloads are refused.
- The human's own clicks, keys and scrolling are seen by an AppKit event
  monitor, so taking control from a worker needs no timing guess.
- Address bar, tabs, back/forward/reload and page-opened windows work.
  Worker click/type/scroll on the Mac come in the next commit.

macOS 13 keeps the headless Chrome frames. Windows is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Workers can now click, type, press keys, choose options, scroll and hover
in the WKWebView over the card, and observe returns the accessibility
tree in the same shape as Playwright's aria snapshot.

- Each input goes straight to the WKWebView as a trusted event, and the
  driver waits until the page has seen it (a counter of trusted events in
  MemCode's own content world) before the next step. Without that wait,
  WebKit could apply a later insertText before an earlier keyDown.
- Clicking a select, file, date, time or color control is refused: WebKit
  answers those with an AppKit menu or panel on screen. Selects go
  through choose, as on the other platforms.
- If a worker click makes the visible card take the keyboard, it goes
  back to whatever had it, unless the human clicked meanwhile.
- The content world is now kept alive. WebKit dropped its state whenever
  the API object was released, so the counter reset on every call.

The tests run the same driver scripts against real Chrome pages through a
host with the Rust module's methods. The scripts were also checked in a
WKWebView: counts, refs, tree, and a fresh counter after navigation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the Mac, a popup that closed itself with window.close() stayed open
as a tab. wry's UI delegate has no webViewDidClose:, so WebKit's request
went unheard. OAuth sign-in popups finished, but left a tab behind.

Each card view now has a small delegate in front of wry's. It notes
webViewDidClose: and forwards every other message to wry's delegate, so
popups, file uploads and the camera and microphone denial work as before.
The next browser call drops the closed view, outside WebKit's callback,
and the runtime closes its tab when browser_pages no longer lists it.

A card's first tab can close itself too when it has one history entry,
as in Chrome.

Unit tests cover the close and the forwarding. A real WKWebView check
confirmed that popups still open through the forwarded delegate and that
both kinds of close are heard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blocksorg

blocksorg Bot commented Nov 23, 2026

Copy link
Copy Markdown

Mention Blocks like a regular teammate with your question or request:

@blocks review this pull request
@blocks make the following changes ...
@blocks create an issue from what was mentioned in the following comment ...
@blocks explain the following code ...
@blocks are there any security or performance concerns?

Run @blocks /help for more information.

Workspace settings | Disable this message

@Alex793x
Alex793x merged commit cb8de3c into dev Nov 23, 2026
1 check passed
Alex793x added a commit that referenced this pull request Nov 23, 2026
… [skip ci]

#19 lists block2 and the objc2 crates as MemCode's own dependencies. They were already in the lock through Tauri, so no notice changes; only the Cargo.lock fingerprint moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Alex793x added a commit that referenced this pull request Nov 23, 2026
… [skip ci]

#19 lists block2 and the objc2 crates as MemCode's own dependencies. They were already in the lock through Tauri, so no notice changes; only the Cargo.lock fingerprint moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant